package com.zlop.model;

/**
 * 需求：
 * 	啤酒2元一瓶，4个瓶盖能换一瓶啤酒，2个空啤酒瓶能换一瓶啤酒。
 * 	问n元钱一共能得到多少瓶啤酒？给出n=10的答案。
 *
 */
public class Winebottle {

	/** 余额  */
	private int balance;
	
	/** 酒 */
	private int wineCount;

	/** 瓶盖 */
	private int capCount;

	/** 酒瓶 */
	private int bottleCount;
	

	/**
	 * 私有构造方法
	 * @param wineCount
	 * @param capCount
	 * @param bottleCount
	 */
	private Winebottle(int balance, int wineCount, int capCount, int bottleCount) {
		this.balance = balance;
		this.wineCount = wineCount;
		this.capCount = capCount;
		this.bottleCount = bottleCount;
	}

	/**
	 * 通过价钱构建对象
	 * @param money
	 * @return
	 */
	public static Winebottle builder(int money) {
		// 一瓶酒一个瓶盖一个空瓶
		int num = money / 2;
		return new Winebottle(money % 2, num, num, num);
	}

	/**
	 * 计算
	 * @return
	 */
	public Winebottle compute() {
		while (capCount > 4 || bottleCount > 1) {
			// 用盖子兑换
			wineCount += capCount / 4;
			// 用空瓶子兑换
			wineCount += bottleCount / 2;

			capCount = capCount / 4 + capCount % 4;
			bottleCount = bottleCount / 2 + bottleCount % 2;
		}
		return this;
	}

	@Override
	public String toString() {
		return "共喝" + wineCount + "瓶啤酒。还剩下余额" + balance + "元，" + capCount + "个瓶盖和" + bottleCount + "个空瓶";
	}

	public int getBalance() {
		return balance;
	}

	public void setBalance(int balance) {
		this.balance = balance;
	}

	public int getWineCount() {
		return wineCount;
	}

	public void setWineCount(int wineCount) {
		this.wineCount = wineCount;
	}

	public int getCapCount() {
		return capCount;
	}

	public void setCapCount(int capCount) {
		this.capCount = capCount;
	}

	public int getBottleCount() {
		return bottleCount;
	}

	public void setBottleCount(int bottleCount) {
		this.bottleCount = bottleCount;
	}

}
